const type = {
  ADD_OPERATION: 'ADD_OPERATION',
  DEL_OPERATION: 'DEL_OPERATION',
};

const state = {
  operation: []
};

const getters = {
  operation: state => state.operation
};

const mutations = {
  [type.ADD_OPERATION](state, operation) {
    if (!state.operation.includes(operation)) {
      state.operation.push(operation)
    }
  },
  [type.DEL_OPERATION](state, operation) {
    state.operation.some((item, index) => {
      if (item === operation) {
        state.operation.splice(index, 1)
        return true
      }
    })
  }
};

const actions = {
  addOperation: ({commit}, operation) => {
    commit(type.ADD_OPERATION, operation)
  },
  delOperation: ({commit}, operation) => {
    commit(type.DEL_OPERATION, operation)
  }
};

export default {
  state,
  getters,
  mutations,
  actions
}
